// Copyright by Scot Drysdale

package cn.edu.nju.software.grapheditor.shape;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
/**@author smy*/
//Completed on May 21th
//Modified on May 28th
public class Rectangle extends Shape {
    public Rectangle(Color c,int smallx,int bigx,int smally,int bigy) {
		super(c);
		this.smallx=smallx;
		this.bigx=bigx;
		this.smally=smally;
		this.bigy=bigy;
		this.centerx=(bigx+smallx)/2;
		this.centery=(bigy+smally)/2;
	}
	private int smallx; //Corners
    private int bigx;
    private int smally;
    private int bigy;
    private int centerx;
    private int centery;
	@Override
	public boolean containsPoint(Point p) {
		if(p.x>=this.smallx && p.x<=this.bigx && p.y>=this.smally && p.y<=this.bigy)return true;
		else return false;
	}
	@Override
	public void drawShape(Graphics page) {
		page.drawRect(smallx, smally, bigx-smallx, bigy-smally);
		page.fillRect(smallx, smally, bigx-smallx, bigy-smally);
	}
	@Override
	public Point getCenter() {
		Point ans=new Point();
		ans.x=centerx;
		ans.y=centery;
		return ans;
	}
	@Override
	public void move(int deltaX, int deltaY) {
		this.smallx+=deltaX;
		this.bigx+=deltaX;
		this.smally+=deltaY;
		this.bigy+=deltaY;
		this.centerx=(bigx+smallx)/2;
		this.centery=(bigy+smally)/2;
	}
	@Override
	public String getclass() {
		return "Rectangle";
	}
	
	public int[] getargs(){
		int[]ans=new int[4];
		ans[0]=this.smallx;
		ans[1]=this.bigx;
		ans[2]=this.smally;
		ans[3]=this.bigy;
		return ans;
		
	}
	
}
